package com.gurun.camera.account.presenter;

import com.danale.sdk.platform.result.countrycode.CountryCodeResult;
import com.gurun.camera.account.model.ObtainCountryModelImpl;
import com.gurun.camera.account.view.ISelectCountryView;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * Created by danal on 2016/9/9.
 */

public class SelectCountryPresenterImpl implements ISelectCountryPresenter {
    private ObtainCountryModelImpl obtainCountryModel;
    private ISelectCountryView selectCountryView;
    public SelectCountryPresenterImpl(ISelectCountryView selectCountryView){
        this.obtainCountryModel = new ObtainCountryModelImpl();
        this.selectCountryView = selectCountryView;
    }


    /**
     * 获取支持的国家国别码
     * Obtain supported country‘s country codes
     */
    @Override
    public void getCountryCodeList() {

        obtainCountryModel.obtainCountryCodelist()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<CountryCodeResult>() {
                    @Override
                    public void call(CountryCodeResult countryCodeResult) {
                        if(selectCountryView != null){
                            selectCountryView.showCountryCodeList(countryCodeResult);
                        }

                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {

                    }
                });

    }

}
